package thread;

public class Demo12 {
   private static boolean isQuit=false;

    public static void main(String[] args) throws InterruptedException {
       // boolean isQuit=false;
        Thread t=new Thread(()->{
            while (!isQuit) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t 线程执行结束");
            });
        t.start();

        Thread.sleep(2000);
        //修改isQuit 变量，就能够影响到t线程结束了
        System.out.println("main 线程尝试终止t线程");
        isQuit=true;


    }
}
